package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"react-blog-server/app/dao"
	"react-blog-server/app/dao/model"
	"react-blog-server/common/response"
)

func NewSquareHttp(group *gin.RouterGroup) {
	group.GET("/square/posts", GetSquarePosts)
	group.GET("/square/categories", GetCategories)
	group.POST("/square/categories", AddCategories)
}

// 获取发布的文章
func GetSquarePosts(c *gin.Context) {
	response.Ok(c)
}

func GetCategories(c *gin.Context) {

}

func AddCategories(c *gin.Context) {
	var category model.Category
	if err := c.BindJSON(&category); err != nil {
		response.Fail(c, http.StatusBadRequest, err.Error())
		return
	}
	if err := dao.DB.Create(&category).Error; err != nil {
		response.Fail(c, http.StatusInternalServerError, err.Error())
		return
	}
	response.Success(c, &category)
}
